package com.appcenter.application.mapper;

import com.appcenter.application.dto.externalapi.BusinessSystemJobDto;
import com.appcenter.application.dto.jobs.JobDto;
import com.appcenter.application.dto.roles.RoleDto;
import com.appcenter.application.model.JobUsers;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;
import tk.mybatis.mapper.common.Mapper;

import java.util.List;
import java.util.Map;

@org.apache.ibatis.annotations.Mapper
@Repository
public interface JobUsersMapper extends Mapper<JobUsers> {

    @Results({
            @Result(column = "orgJobId", property = "org", one = @One(select = "com.appcenter.application.mapper.OrgJobsMapper.getOrgByOrgJobId"))
    })
    @Select("<script>" +
           " select j.*,ju.OrgJobId as orgJobId,ju.Main from jobs j " +
            "inner join orgjobs oj on j.Id=oj.JobId "+
            "inner join jobusers ju on ju.OrgJobId=oj.Id AND j.ValidStatus=1 and j.Deleted=0"+
           " inner join jobcategorys g on g.Id=j.JobCategoryId AND g.ValidStatus=1 and g.Deleted=0"+
           " WHERE  j.VersionNo=#{versionNo} AND ju.VersionNo=#{versionNo} AND ju.UserId=#{userId} and g.AppCode=#{appCode}"+
            "" +
            "</script>")
    public List<JobDto> getJobsByUserId(Map<String,Object> param);






    @Results({
            @Result(column = "orgJobId", property = "orgs", one = @One(select = "com.appcenter.application.mapper.OrgJobsMapper.getBusinessSystemOrg"))
    })
    @Select("<script>" +
            " select j.*,ju.OrgJobId as orgJobId from jobs j " +
            "inner join orgjobs oj on j.Id=oj.JobId "+
            "inner join jobusers ju on ju.OrgJobId=oj.Id AND j.ValidStatus=1 and j.Deleted=0"+
            " inner join jobcategorys g on g.Id=j.JobCategoryId AND g.ValidStatus=1 and g.Deleted=0"+
            " WHERE  j.VersionNo=#{versionNo} AND ju.VersionNo=#{versionNo} AND ju.UserId=#{userId} and g.AppCode=#{appCode}"+
            "" +
            "</script>")
    public List<BusinessSystemJobDto> getBusinessSystemJob(Map<String,Object> param);
}
